<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%@ include file="/WEB-INF/common/public.jspf"%>
		<%@ include file="/WEB-INF/common/easyui.jspf"%>

		<title>查询列表</title>
	</head>

	<body>
		<script type="text/javascript">
			$(function() {

				$('#list').datagrid({
					url: '/course/getCourseList',
					pagination: true,
					fitColumns: true,
					method:"get",
					striped: true,
					idField: 'courseId',
					loadMsg: '正在加载数据,请稍等.',
					rownumbers: true,
					fit: true,
					remoteSort: false,
					columns: [
						[{
							checkbox: true
						},{
							field: 'courseId',
							title: '课程编号',
							sortable: true,
							width: 300,
						},{
							field: 'courseName',
							title: '课程名称',
							sortable: true,
							width: 300
						}]
					],
					toolbar: [{
						text: '刷新',
						iconCls:'icon-reload',
						handler:function (){
							$('#list').datagrid("reload");
							$('#list').datagrid("clearSelections");
						}
					},{
						iconCls: 'icon-remove',
						text:'删除',
						handler: function(){
							var s=$('#list').datagrid("getSelections");
							if(s.length == 0){
								alert("至少选择一门课程");
								return ;
							}
							var pids = new Array();
							for(var i=0;i<s.length;i++){
								pids[i]=s[i].courseId;
							}
							$.ajax({
								type:"post",
								traditional:true,
								url: "/course/delete",
								async:true,
								data:{pids:pids},
								success: function(data) {
									if(!data.success){
										$.messager.alert("提示","删除失败,请与管理员联系","warning");
										return ;
									}
									
									$('#list').datagrid("reload");
									$('#list').datagrid("clearSelections");
									$.messager.alert("提示","删除成功","info");
									
								}
							});
							
							
						}
					},'-',{
						iconCls: 'icon-edit',
						text:'更新',
						handler: function(){
							var s=$('#list').datagrid("getSelections");
							if(s.length == 0){
								alert("选择一门课程");
								return ;
							}else if(s.length >1){
								alert("只能选择一门课程");
								return ;
							}
							var row=s[0];
							 parent.$("#win").dialog({  
									title: '更新',    
								    width: 380,    
								    height: 250,    
								    closed: false,    
								    cache: false,
								    modal:true,
								    draggable:false,
								    collapsible:false,
								    content:"<iframe  src='/course/updateCourse?courseId="+row.courseId+"&courseName=" +row.courseName+"&update=0'  title='更新课程信息' height='100%' width='100%' frameborder='0' ></iframe>"
 
							 });
							
						}
					}]

					
				});
				
				

			})
		</script>
		<table id="list"></table>
		
	</body>

</html>